using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;

namespace ZX.BLL.ClientMobi.Message
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class DatSysNewsInfo
    {
        #region 属性
        private String _iD = Guid.NewGuid().ToString();
        /// <summary>
        /// 
        /// </summary>
        public String ID
        {
            get{return _iD;}
            set{_iD = value;}
        }
        
        private string _proposer = "";
        /// <summary>
        /// 申请人
        /// </summary>
        public string Proposer
        {
            get{return _proposer;}
            set{_proposer = value;}
        }
        
        private string _filiale = "";
        /// <summary>
        /// 所属分公司
        /// </summary>
        public string Filiale
        {
            get{return _filiale;}
            set{_filiale = value;}
        }
        
        private string _deptID = "";
        /// <summary>
        /// 所属部门ID
        /// </summary>
        public string DeptID
        {
            get{return _deptID;}
            set{_deptID = value;}
        }
        
        private string _deptName = "";
        /// <summary>
        /// 所属部门
        /// </summary>
        public string DeptName
        {
            get{return _deptName;}
            set{_deptName = value;}
        }
        
        private string _postID = "";
        /// <summary>
        /// 所属岗位ID
        /// </summary>
        public string PostID
        {
            get{return _postID;}
            set{_postID = value;}
        }
        
        private string _postName = "";
        /// <summary>
        /// 所属岗位
        /// </summary>
        public string PostName
        {
            get{return _postName;}
            set{_postName = value;}
        }
        
        private string _createdTime = "";
        /// <summary>
        /// 申请时间
        /// </summary>
        public string CreatedTime
        {
            get{return _createdTime;}
            set{_createdTime = value;}
        }
        
        private string _workFlowId = "";
        /// <summary>
        /// 流程模板ID
        /// </summary>
        public string WorkFlowId
        {
            get{return _workFlowId;}
            set{_workFlowId = value;}
        }
        
        private string _workFlowInsId = "";
        /// <summary>
        /// 流程实例ID
        /// </summary>
        public string WorkFlowInsId
        {
            get{return _workFlowInsId;}
            set{_workFlowInsId = value;}
        }
        
        private string _workTaskId = "";
        /// <summary>
        /// 流程模板任务ID
        /// </summary>
        public string WorkTaskId
        {
            get{return _workTaskId;}
            set{_workTaskId = value;}
        }
        
        private string _workTaskInsId = "";
        /// <summary>
        /// 流程任务实例ID
        /// </summary>
        public string WorkTaskInsId
        {
            get{return _workTaskInsId;}
            set{_workTaskInsId = value;}
        }
        
        private string _bpmTitle = "";
        /// <summary>
        /// 标题
        /// </summary>
        public string BpmTitle
        {
            get{return _bpmTitle;}
            set{_bpmTitle = value;}
        }
        
        private String _addUser = Guid.NewGuid().ToString();
        /// <summary>
        /// 发送人编号
        /// </summary>
        public String AddUser
        {
            get{return _addUser;}
            set{_addUser = value;}
        }
        
        private DateTime _createDate = DateTime.Parse("1900-1-1");
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDate
        {
            get{return _createDate;}
            set{_createDate = value;}
        }
        
        private string _title = "";
        /// <summary>
        /// 消息标题
        /// </summary>
        public string Title
        {
            get{return _title;}
            set{_title = value;}
        }
        
        private string _content = "";
        /// <summary>
        /// 消息内容
        /// </summary>
        public string Content
        {
            get{return _content;}
            set{_content = value;}
        }
        
        private string _recevePeopleName = "";
        /// <summary>
        /// 接收人的名字
        /// </summary>
        public string RecevePeopleName
        {
            get{return _recevePeopleName;}
            set{_recevePeopleName = value;}
        }
        
        private string _createPeopleName = "";
        /// <summary>
        /// 发送人名称
        /// </summary>
        public string CreatePeopleName
        {
            get{return _createPeopleName;}
            set{_createPeopleName = value;}
        }
        
        private string _sendMode = "";
        /// <summary>
        /// 发送方式
        /// </summary>
        public string SendMode
        {
            get{return _sendMode;}
            set{_sendMode = value;}
        }
        
        private bool _iSDelete = false;
        /// <summary>
        /// 是否删除【0，未删除；1删除】
        /// </summary>
        public bool ISDelete
        {
            get{return _iSDelete;}
            set{_iSDelete = value;}
        }
        
        private int _priority = 0;
        /// <summary>
        /// 优先级:0、正常    1、紧急
        /// </summary>
        public int Priority
        {
            get{return _priority;}
            set{_priority = value;}
        }
        
        private int _classify = 0;
        /// <summary>
        /// 分类
        /// </summary>
        public int Classify
        {
            get{return _classify;}
            set{_classify = value;}
        }

        #region Alter :消息列表外部支持字段 by Yinlong 2014/11/13

        /// <summary>
        /// 子级关系总数量
        /// </summary>
        private int _ChildCX=0;

        public int ChildCX
        {
            get { return _ChildCX; }
            set { _ChildCX = value; }
        }

        /// <summary>
        /// 回复列表
        /// </summary>
        private IList<MsgReplyInfo> _MsgReplyInstance=null;

        public IList<MsgReplyInfo> MsgReplyInstance
        {
            get { 
                if(_MsgReplyInstance==null)
                    _MsgReplyInstance = new List<MsgReplyInfo>();

                return _MsgReplyInstance;
            }
            set { _MsgReplyInstance = value; }
        }
        #endregion
        #endregion

        #region 构造函数
        public DatSysNewsInfo()
        {}
        
        public DatSysNewsInfo
        (
            String iD,
            string proposer,
            string filiale,
            string deptID,
            string deptName,
            string postID,
            string postName,
            string createdTime,
            string workFlowId,
            string workFlowInsId,
            string workTaskId,
            string workTaskInsId,
            string bpmTitle,
            String addUser,
            DateTime createDate,
            string title,
            string content,
            string recevePeopleName,
            string createPeopleName,
            string sendMode,
            bool iSDelete,
            int priority,
            int classify
        )
        {
            _iD = iD;
            _proposer = proposer;
            _filiale = filiale;
            _deptID = deptID;
            _deptName = deptName;
            _postID = postID;
            _postName = postName;
            _createdTime = createdTime;
            _workFlowId = workFlowId;
            _workFlowInsId = workFlowInsId;
            _workTaskId = workTaskId;
            _workTaskInsId = workTaskInsId;
            _bpmTitle = bpmTitle;
            _addUser = addUser;
            _createDate = createDate;
            _title = title;
            _content = content;
            _recevePeopleName = recevePeopleName;
            _createPeopleName = createPeopleName;
            _sendMode = sendMode;
            _iSDelete = iSDelete;
            _priority = priority;
            _classify = classify;
        }
        #endregion
        
        #region 填充数据实体
        /// <summary>
        /// 得到DatSysNewsInfo数据实体
        /// </summary>
        /// <param name="row">row</param>
        /// <returns>DatSysNewsInfo数据实体</returns>
        public static DatSysNewsInfo PopulateFromDataRow(DataRow row)
        {
            DatSysNewsInfo obj = new DatSysNewsInfo();
            if (row != null)
            {
                obj.ID = row["ID"] == DBNull.Value ? Guid.NewGuid().ToString() : Convert.ToString(row["ID"]);   
                obj.Proposer = row["Proposer"] == DBNull.Value ? "" : Convert.ToString(row["Proposer"]);   
                obj.Filiale = row["Filiale"] == DBNull.Value ? "" : Convert.ToString(row["Filiale"]);   
                obj.DeptID = row["DeptID"] == DBNull.Value ? "" : Convert.ToString(row["DeptID"]);   
                obj.DeptName = row["DeptName"] == DBNull.Value ? "" : Convert.ToString(row["DeptName"]);   
                obj.PostID = row["PostID"] == DBNull.Value ? "" : Convert.ToString(row["PostID"]);   
                obj.PostName = row["PostName"] == DBNull.Value ? "" : Convert.ToString(row["PostName"]);   
                obj.CreatedTime = row["CreatedTime"] == DBNull.Value ? "" : Convert.ToString(row["CreatedTime"]);   
                obj.WorkFlowId = row["WorkFlowId"] == DBNull.Value ? "" : Convert.ToString(row["WorkFlowId"]);   
                obj.WorkFlowInsId = row["WorkFlowInsId"] == DBNull.Value ? "" : Convert.ToString(row["WorkFlowInsId"]);   
                obj.WorkTaskId = row["WorkTaskId"] == DBNull.Value ? "" : Convert.ToString(row["WorkTaskId"]);   
                obj.WorkTaskInsId = row["WorkTaskInsId"] == DBNull.Value ? "" : Convert.ToString(row["WorkTaskInsId"]);   
                obj.BpmTitle = row["bpmTitle"] == DBNull.Value ? "" : Convert.ToString(row["bpmTitle"]);   
                obj.AddUser = row["AddUser"] == DBNull.Value ? Guid.NewGuid().ToString() : Convert.ToString(row["AddUser"]);   
                obj.CreateDate = row["createDate"] == DBNull.Value ? DateTime.Parse("1900-1-1") : Convert.ToDateTime(row["createDate"]);   
                obj.Title = row["title"] == DBNull.Value ? "" : Convert.ToString(row["title"]);   
                obj.Content = row["content"] == DBNull.Value ? "" : Convert.ToString(row["content"]);   
                obj.RecevePeopleName = row["recevePeopleName"] == DBNull.Value ? "" : Convert.ToString(row["recevePeopleName"]);   
                obj.CreatePeopleName = row["createPeopleName"] == DBNull.Value ? "" : Convert.ToString(row["createPeopleName"]);   
                obj.SendMode = row["sendMode"] == DBNull.Value ? "" : Convert.ToString(row["sendMode"]);   
                obj.ISDelete = row["ISDelete"] == DBNull.Value ? false : Convert.ToBoolean(row["ISDelete"]);   
                obj.Priority = row["Priority"] == DBNull.Value ? 0 : Convert.ToInt32(row["Priority"]);   
                obj.Classify = row["Classify"] == DBNull.Value ? 0 : Convert.ToInt32(row["Classify"]);   
            }
            else
            {
                return null;
            }
            return obj;
        }
        
        /// <summary>
        /// 得到DatSysNewsInfo数据实体
        /// </summary>
        /// <param name="reader">reader</param>
        /// <returns>DatSysNewsInfo数据实体</returns>
        public static DatSysNewsInfo PopulateFromReader(IDataReader reader)
        {
            DatSysNewsInfo obj = new DatSysNewsInfo();
            
            obj.ID = reader["ID"] == DBNull.Value ? Guid.NewGuid().ToString() : Convert.ToString(reader["ID"]);
            obj.Proposer = reader["Proposer"] == DBNull.Value ? "" : Convert.ToString(reader["Proposer"]);
            obj.Filiale = reader["Filiale"] == DBNull.Value ? "" : Convert.ToString(reader["Filiale"]);
            obj.DeptID = reader["DeptID"] == DBNull.Value ? "" : Convert.ToString(reader["DeptID"]);
            obj.DeptName = reader["DeptName"] == DBNull.Value ? "" : Convert.ToString(reader["DeptName"]);
            obj.PostID = reader["PostID"] == DBNull.Value ? "" : Convert.ToString(reader["PostID"]);
            obj.PostName = reader["PostName"] == DBNull.Value ? "" : Convert.ToString(reader["PostName"]);
            obj.CreatedTime = reader["CreatedTime"] == DBNull.Value ? "" : Convert.ToString(reader["CreatedTime"]);
            obj.WorkFlowId = reader["WorkFlowId"] == DBNull.Value ? "" : Convert.ToString(reader["WorkFlowId"]);
            obj.WorkFlowInsId = reader["WorkFlowInsId"] == DBNull.Value ? "" : Convert.ToString(reader["WorkFlowInsId"]);
            obj.WorkTaskId = reader["WorkTaskId"] == DBNull.Value ? "" : Convert.ToString(reader["WorkTaskId"]);
            obj.WorkTaskInsId = reader["WorkTaskInsId"] == DBNull.Value ? "" : Convert.ToString(reader["WorkTaskInsId"]);
            obj.BpmTitle = reader["bpmTitle"] == DBNull.Value ? "" : Convert.ToString(reader["bpmTitle"]);
            obj.AddUser = reader["AddUser"] == DBNull.Value ? Guid.NewGuid().ToString() : Convert.ToString(reader["AddUser"]);
            obj.CreateDate = reader["createDate"] == DBNull.Value ? DateTime.Parse("1900-1-1") : Convert.ToDateTime(reader["createDate"]);
            obj.Title = reader["title"] == DBNull.Value ? "" : Convert.ToString(reader["title"]);
            obj.Content = reader["content"] == DBNull.Value ? "" : Convert.ToString(reader["content"]);
            obj.RecevePeopleName = reader["recevePeopleName"] == DBNull.Value ? "" : Convert.ToString(reader["recevePeopleName"]);
            obj.CreatePeopleName = reader["createPeopleName"] == DBNull.Value ? "" : Convert.ToString(reader["createPeopleName"]);
            obj.SendMode = reader["sendMode"] == DBNull.Value ? "" : Convert.ToString(reader["sendMode"]);
            obj.ISDelete = reader["ISDelete"] == DBNull.Value ? false : Convert.ToBoolean(reader["ISDelete"]);
            obj.Priority = reader["Priority"] == DBNull.Value ? 0 : Convert.ToInt32(reader["Priority"]);
            obj.Classify = reader["Classify"] == DBNull.Value ? 0 : Convert.ToInt32(reader["Classify"]);
            
            return obj;
        }
        
        /// <summary>
        /// 得到DatSysNews，DataTable
        /// </summary>
        /// <param name="info">info</param>
        /// <returns>DatSysNews，DataTable</returns>
        public static DataTable PopulateFromInfo(DatSysNewsInfo info)
        {
            DataTable table = new DataTable("DatSysNews");
            DataRow row = null;
            
            if (info != null)
            {
                
                table.Columns.Add("ID", typeof(String));
                table.Columns.Add("Proposer", typeof(string));
                table.Columns.Add("Filiale", typeof(string));
                table.Columns.Add("DeptID", typeof(string));
                table.Columns.Add("DeptName", typeof(string));
                table.Columns.Add("PostID", typeof(string));
                table.Columns.Add("PostName", typeof(string));
                table.Columns.Add("CreatedTime", typeof(string));
                table.Columns.Add("WorkFlowId", typeof(string));
                table.Columns.Add("WorkFlowInsId", typeof(string));
                table.Columns.Add("WorkTaskId", typeof(string));
                table.Columns.Add("WorkTaskInsId", typeof(string));
                table.Columns.Add("bpmTitle", typeof(string));
                table.Columns.Add("AddUser", typeof(String));
                table.Columns.Add("createDate", typeof(DateTime));
                table.Columns.Add("title", typeof(string));
                table.Columns.Add("content", typeof(string));
                table.Columns.Add("recevePeopleName", typeof(string));
                table.Columns.Add("createPeopleName", typeof(string));
                table.Columns.Add("sendMode", typeof(string));
                table.Columns.Add("ISDelete", typeof(bool));
                table.Columns.Add("Priority", typeof(int));
                table.Columns.Add("Classify", typeof(int));
            
                row = table.NewRow();
            
                row["ID"] = info.ID;
                row["Proposer"] = info.Proposer;
                row["Filiale"] = info.Filiale;
                row["DeptID"] = info.DeptID;
                row["DeptName"] = info.DeptName;
                row["PostID"] = info.PostID;
                row["PostName"] = info.PostName;
                row["CreatedTime"] = info.CreatedTime;
                row["WorkFlowId"] = info.WorkFlowId;
                row["WorkFlowInsId"] = info.WorkFlowInsId;
                row["WorkTaskId"] = info.WorkTaskId;
                row["WorkTaskInsId"] = info.WorkTaskInsId;
                row["bpmTitle"] = info.BpmTitle;
                row["AddUser"] = info.AddUser;
                row["createDate"] = info.CreateDate;
                row["title"] = info.Title;
                row["content"] = info.Content;
                row["recevePeopleName"] = info.RecevePeopleName;
                row["createPeopleName"] = info.CreatePeopleName;
                row["sendMode"] = info.SendMode;
                row["ISDelete"] = info.ISDelete;
                row["Priority"] = info.Priority;
                row["Classify"] = info.Classify;
                table.Rows.Add(row);
            }

            return table;
        }
        
        /// <summary>
        /// 得到DatSysNews，DataTable
        /// </summary>
        /// <param name="infoList">infoList</param>
        /// <returns>DatSysNews，DataTable</returns>
        public static DataTable PopulateFromInfoList(List< DatSysNewsInfo> infoList)
        {
            DataTable table = new DataTable("DatSysNews");
            DataRow row = null;
            
            if (infoList != null)
            {
                
                table.Columns.Add("ID", typeof(String));
                table.Columns.Add("Proposer", typeof(string));
                table.Columns.Add("Filiale", typeof(string));
                table.Columns.Add("DeptID", typeof(string));
                table.Columns.Add("DeptName", typeof(string));
                table.Columns.Add("PostID", typeof(string));
                table.Columns.Add("PostName", typeof(string));
                table.Columns.Add("CreatedTime", typeof(string));
                table.Columns.Add("WorkFlowId", typeof(string));
                table.Columns.Add("WorkFlowInsId", typeof(string));
                table.Columns.Add("WorkTaskId", typeof(string));
                table.Columns.Add("WorkTaskInsId", typeof(string));
                table.Columns.Add("bpmTitle", typeof(string));
                table.Columns.Add("AddUser", typeof(String));
                table.Columns.Add("createDate", typeof(DateTime));
                table.Columns.Add("title", typeof(string));
                table.Columns.Add("content", typeof(string));
                table.Columns.Add("recevePeopleName", typeof(string));
                table.Columns.Add("createPeopleName", typeof(string));
                table.Columns.Add("sendMode", typeof(string));
                table.Columns.Add("ISDelete", typeof(bool));
                table.Columns.Add("Priority", typeof(int));
                table.Columns.Add("Classify", typeof(int));
                
                for(int i = 0; i < infoList.Count; i++)
                {
                    row = table.NewRow();
                
                    row["ID"] = infoList[i].ID;
                    row["Proposer"] = infoList[i].Proposer;
                    row["Filiale"] = infoList[i].Filiale;
                    row["DeptID"] = infoList[i].DeptID;
                    row["DeptName"] = infoList[i].DeptName;
                    row["PostID"] = infoList[i].PostID;
                    row["PostName"] = infoList[i].PostName;
                    row["CreatedTime"] = infoList[i].CreatedTime;
                    row["WorkFlowId"] = infoList[i].WorkFlowId;
                    row["WorkFlowInsId"] = infoList[i].WorkFlowInsId;
                    row["WorkTaskId"] = infoList[i].WorkTaskId;
                    row["WorkTaskInsId"] = infoList[i].WorkTaskInsId;
                    row["bpmTitle"] = infoList[i].BpmTitle;
                    row["AddUser"] = infoList[i].AddUser;
                    row["createDate"] = infoList[i].CreateDate;
                    row["title"] = infoList[i].Title;
                    row["content"] = infoList[i].Content;
                    row["recevePeopleName"] = infoList[i].RecevePeopleName;
                    row["createPeopleName"] = infoList[i].CreatePeopleName;
                    row["sendMode"] = infoList[i].SendMode;
                    row["ISDelete"] = infoList[i].ISDelete;
                    row["Priority"] = infoList[i].Priority;
                    row["Classify"] = infoList[i].Classify;
                    table.Rows.Add(row);
                }
            }

            return table;
        }
        
        /// <summary>
        /// Copy得到DatSysNewsInfo，对象
        /// </summary>
        /// <param name="data">data</param>
        /// <returns>DatSysNews，对象</returns>
        public static DatSysNewsInfo CopyData<T>(T data) where T : class
        {
            if (data == null) return null;
            
            DatSysNewsInfo info = new DatSysNewsInfo();
            PropertyInfo[] infoProList = info.GetType().GetProperties();
            PropertyInfo[] dataProList = data.GetType().GetProperties();
            
            foreach (PropertyInfo infoPro in infoProList)
            {
                foreach (PropertyInfo dataPro in dataProList)
                {
                    if (infoPro.Name == dataPro.Name && infoPro.PropertyType.FullName == dataPro.PropertyType.FullName)
                    {
                        infoPro.SetValue(info, dataPro.GetValue(data, null), null);
                    }
                }
            }
            
            return info;
        }
        
        #endregion
    }
}


